/*
 * 用户修改菜单交易
 * 参数   交易码：trancode=90043,菜单名：name，菜单连接:url，父级菜单：pid
 * 
 */

package org.ccams.tran;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;

import org.ccams.domain.InsertHelp;
import org.ccams.domain.User;
import org.ccams.web.UserSession;

public class Tran90043 extends AbstractJsonTran {

	@SuppressWarnings("unchecked")
	public void buildJSONObject(Map model, JSONObject json,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// 获得用户录入信息
		String idt_salesorders_h=request.getParameter("id");//获得修改项Id
		String customer_name = (String) request.getParameter("customer_name");
		String idtOrdertype = (String) request.getParameter("idtOrdertype");
		String idtDept = (String) request.getParameter("idtDept");		
		String salesChannelCode = (String) request.getParameter("salesChannelCode");
		String idtPricelist = (String) request.getParameter("idtPricelist");
		String ordered_date = (String) request.getParameter("ordered_date");
		String username1 = (String) request.getParameter("username1");
		String username2 = (String) request.getParameter("username2");
		String meaning = (String) request.getParameter("meaning");
		String order_money = (String) request.getParameter("order_money");
		String remark = (String) request.getParameter("remark");
		
		//获得订单修改人
		HttpSession session = request.getSession();
		UserSession userSession = (UserSession)session.getAttribute("userSession");
		User user = userSession.getUser();
		String update_user=user.getUserName();
	
		InsertHelp insertHelp=new InsertHelp();
		//字符串空值处理
		remark = (remark != null) ? remark : "";			
		if(idtPricelist==null||idtPricelist.equals("")){
			insertHelp.setFreight_terms_id(new Integer(0));
		}else{
			insertHelp.setIdtPricelist(new Integer(idtPricelist));
		}
		insertHelp.setId(Integer.parseInt(idt_salesorders_h));
		insertHelp.setCustomer_name(customer_name);
		insertHelp.setOrdertype_id(new Integer(idtOrdertype));
		insertHelp.setIdtDept(Integer.parseInt(idtDept));
		insertHelp.setMeaning(meaning);
		insertHelp.setOrdered_date(ordered_date);		
		insertHelp.setUsername1(username1);
		insertHelp.setUsername2(username2);
		insertHelp.setRemark(remark);
		insertHelp.setLast_update_user(update_user);
		insertHelp.setSalesChannelCode(salesChannelCode);
		insertHelp.setIdtPricelist(Integer.parseInt(idtPricelist));
		insertHelp.setOrder_money(new BigDecimal(order_money));
		insertHelp.setState(0);
		
		HashMap<String, Object> jsonMap = new HashMap<String, Object>();
		boolean success = false;
		String message = "";
		int i = getCcamsService().getTsalesordershDao().updateByPrimaryKey(insertHelp);
		if (i == 1) {
			success = true;
			message = "业务订单修改成功";
		} else {
			success = false;
			message = "业务订单修改失败";
		}
		jsonMap.put("success", success);
		jsonMap.put("message", message);
		json.putAll(jsonMap);
	}
}
